package com.boco.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.boco.entity.EMR_MJZZLXJPYBG;

public class GetEMR_MJZZLXJPYBGData {
	
	private static final Log log = LogFactory.getLog(GetEMR_MJZZLXJPYBGData.class);
	public static List<EMR_MJZZLXJPYBG> getData()
	{
	    Connection con = null;
	    PreparedStatement pre = null;
	    ResultSet result = null;
	    List<EMR_MJZZLXJPYBG> re = new ArrayList<EMR_MJZZLXJPYBG>();
	    try
	    {
	        Class.forName("oracle.jdbc.driver.OracleDriver");
	        System.out.println("开始尝试连接数据库！");
	        String url = "jdbc:oracle:" + "thin:@172.20.21.12:1521:orcl";
	        String user = "sjzx_hxk";
	        String password = "boco#1234";
	        con = DriverManager.getConnection(url, user, password);
	        System.out.println("连接成功！");
	        
	        String sql = "select "
	        		+"'' as HZZSYH,"
					+"a.yljgdm as YLJGZZJGDM,"
					+"'' as YLJGMC,"
					+"b.jzlsh as MJZH,"
					//长度23 对方20 超长置为空
					+"'' as MJZZLYPMYLSH,"
					+"b.brxm as XM,"
					+"'' as XBDM,"
					+"b.brxb as XB,"
					+"'' as CSRQ,"
					+"b.brnl as SZNL,"
					+"b.jzlsh as JZLSH,"
					+"'' as JYSQDH,"
					+"a.bgdh as JYBGDH,"
					+"a.xjdh as XJDH,"
					+"a.xjmc as XJMC,"
					+"c.ymdm as YMDM,"
					+"c.ymmc as YMMC,"
					+"'' as KYJGDM,"
					+"'' as KYJG,"
					+"'' as CKZ,"
					+"'' as JYFF,"
					+"'' as JYJG,"
					+"'' as DYXH,"
					+"'' as JYJGDM,"
					+"'' as JYJGMC,"
					+"'' as ORGCODE,"
					+"'' as AREACODE,"
					+"to_char(sysdate,'yyyyMMddHH24miss') as UPLOADTIME,"
					+"'' as  SOURCEID "
					+" from TB_LIS_XJJG a left join TB_LIS_JYBG b" 
					+" on a.yljgdm = b.yljgdm "
					+" and a.bgdh= b.bgdh left join TB_LIS_YMJG c "
					+" on b.yljgdm = c.yljgdm and b.bgdh = c.bgdh ";
	 
	        log.info("查询sql："+sql);
	        pre = con.prepareStatement(sql);
	        result = pre.executeQuery();
	        System.out.println("执行成功");
	        while (result.next()){
//	            System.out.println(result.getInt("YYDAH"));
	        	EMR_MJZZLXJPYBG temp = new EMR_MJZZLXJPYBG();
	        
	        	temp.setHZZSYH(result.getString("HZZSYH"));
	        	temp.setYLJGZZJGDM(result.getString("YLJGZZJGDM"));
	        	temp.setYLJGMC(result.getString("YLJGMC"));
	        	temp.setMJZH(result.getString("MJZH"));
	        	temp.setMJZZLYPMYLSH(result.getString("MJZZLYPMYLSH"));
	        	
	        	temp.setXM(result.getString("XM"));
	        	temp.setXBDM(result.getString("XBDM"));
	        	temp.setXB(result.getString("XB"));
	        	temp.setCSRQ(result.getString("CSRQ"));
	        	temp.setSZNL(result.getString("SZNL"));
	        	temp.setJZLSH(result.getString("JZLSH"));
	        	temp.setJYSQDH(result.getString("JYSQDH"));
	        	temp.setJYBGDH(result.getString("JYBGDH"));
	        	temp.setXJDH(result.getString("XJDH"));
	        	temp.setXJMC(result.getString("XJMC"));
	        	temp.setYMDM(result.getString("YMDM"));
	        	temp.setYMMC(result.getString("YMMC"));
	        	temp.setKYJGDM(result.getString("KYJGDM"));
	        	temp.setKYJG(result.getString("KYJG"));
	        	temp.setCKZ(result.getString("CKZ"));
	        	temp.setJYFF(result.getString("JYFF"));
	        	temp.setJYJG(result.getString("JYJG"));
	        	temp.setDYXH(result.getString("DYXH"));
	        	temp.setJYJGDM(result.getString("JYJGDM"));
	        	temp.setJYJGMC(result.getString("JYJGMC"));
	        	
	        	temp.setORGCODE(result.getString("ORGCODE"));
	        	temp.setAREACODE(result.getString("AREACODE"));
	        	temp.setUPLOADTIME(result.getString("UPLOADTIME"));
	        	temp.setSOURCEID(result.getString("SOURCEID"));
	        	re.add(temp);
	        }
	    }
	    catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    finally
	    {
	        try
	        {
	            if (result != null)
	                result.close();
	            if (pre != null)
	                pre.close();
	            if (con != null)
	                con.close();
	            System.out.println("数据库连接已关闭！");
	        }
	        catch (Exception e)
	        {
	            e.printStackTrace();
	        }
	    }
		return re;
	}
}
